import { defineConfig } from 'umi';
import LodashWebpackPlugin from 'lodash-webpack-plugin';

import Constant from './constant';
import Theme from './theme';

const { theme } = require('antd/lib');
const { convertLegacyToken, defaultTheme } = require('@ant-design/compatible/lib');

const { defaultAlgorithm, defaultSeed } = theme;

const mapV5Token = defaultAlgorithm(defaultSeed);
const v5Vars = convertLegacyToken(mapV5Token);

const chainWebpack = config => {
  config.plugin('lodash').use(LodashWebpackPlugin, [
    {
      collections: true,
      paths: true,
    },
  ]);
  
};

// https://umijs.org/zh-CN/plugins/api
const plugins = {
  antd: {
    // import: false, // 升级 antd v5 ＋的
    dark: false,
    compact: false,
  },
  dva: {
  },
  locale: {
    baseSeparator: '-',
    default: 'zh-CN',
    antd: true,
    title: true,
    baseNavigator: true,
  },
};

const define = {
  'process.env.NODE_ENV': process.env.NODE_ENV,
  ...Constant,
};

// https://umijs.org/config/
export default defineConfig({
  // alias: {},
  // analyze: {},
  // autoprefixer: { flexbox: 'no-2009' },
  // base: '/',
  chainWebpack,
  // chunks: ['umi'],
  cssLoader: {
    modules: {
      getLocalIdent: (context, localIdentName, localName, options) => {
        if (context.resourcePath.includes('node_modules') || context.resourcePath.includes('global.less')) {
          return localName;
        }
      },
    },
  },
  // cssModulesTypescriptLoader: ,
  // cssnano: {},
  // copy: [],
  define,
  // devServer: {},
  // devtool: ,
  
  // exportStatic: { htmlSuffix: false, dynamicRoot: false },
  // externals: {},
  extraBabelPlugins: ['lodash'],
  // extraBabelPresets: [],
  // extraPostCSSPlugins: [],
  // favicon: '/assets/favicon.ico',
  // forkTSCheker: {},
  // fastRefresh: true,
  hash: true,
  // headScripts: [{}, ''],
  history: { type: 'browser' }, // browser、hash、memory
  ignoreMomentLocale: true,
  // inlineLimit: 10000,
  // lessLoader: {},
  // links: [{}],
  // manifest: {
  //   fileName: 'manifest.json',
  //   publicPath: ,
  //   basePath: '/',
  // },
  // metas: [{}],
  // mock: {
  //   exclude: [],
  // },
  // mountElementId: 'root',
  // mpa: {},
  // nodeModulesTransform: { type: 'all' },
  // outputPath: 'dist',
  // plugins: [],
  // polyfill: { imports: [] },
  // postcssLoader: {},
  // presets: [],
  proxy: {
    '/api':{
      target:'http://127.0.0.1:8008',
      // target:'http://47.115.201.167:8008',
      changeOrigin:true,
    },
  },
  // 使用document.js作为根文件
  // exportStatic:true,
  // Document: './document.ejs',
  // headScripts: [`window._AMapSecurityConfig = {
  //   securityJsCode: "ddb58e025720d1cbd084c15c08ad3e5c",
  // };`, `https://webapi.amap.com/loader.js`],
  publicPath: '/',
  // routes: [],
  // runtimeHistory: {},
  // runtimePublicPath: false,
  // scripts: [{}, ''],
  // singular: false,
  // ssr: false,
  // styleLoader: {},
  // styles: [],
  targets: { chrome: 49, firefox: 45, safari: 10, edge: 13, ios: 10 },
  // terserOptions: {},
  theme: Theme,
  title: 'ROUTES',
  // webpack5: {},
  mfsu:{},
  // mfsu: { production: { output: '.mfsu-production' } },  // 生产环境
  ...plugins,
});
